/*
 *  $Id: Incinerate.cs 1189 2010-11-12 14:40:06Z thenn.erannor $
 *  This file is a part of Ragima CCG.
 *  (C) 2008 Ragima development group.
 *
 *  Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;
using System.Collections.Generic;

using Ragima.Helper;

namespace Ragima.Cards001.Fire.Spells {
    public class Incinerate : SpellCard {
        public Incinerate() : base("001_f_s_incinerate") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Fire;
            Value = 100;
            AllowInOffence = false;
            AllowInDefence = true;
            AddManaCost(ElementType.Fire, 1);
        }

        public override void DoAction(TargetArgs args) {
            List<Creature> targets = new List<Creature>(args.Player.Enemy.GetAttackers());
            int mana = args.Player.GetMana(ElementType.Fire);
            if (targets.Count == 0 || mana == 0)
                return;
            args.Player.DecrementMana(ElementType.Fire, mana);
            int dmg = mana / targets.Count, rem = mana % targets.Count;
            if (rem > 0)
                dmg++;
            foreach (Creature cr in targets) {
                MercilessFire.DoFireDamage(args.Player, this, cr, dmg);
                if (rem > 0) {
                    rem--;
                    if (rem == 0)
                        dmg--;
                }
                Region region = cr.FindRegion();

                UI.ParticleInfo info = new UI.ParticleInfo(Data.Particles.Vlines01);
                info.AddPhase(0, 20, 0xFF933C.ToColor(), 0.7, 0.6, 0, UI.ParticleTrajectory.Line(-90, 1.3));
                info.AddPhase(50, 0, 0xFA733C.ToColor(), 0.2, 0.4);
                UI.ParticleEmitterInfo emitter = new UI.ParticleEmitterInfo();
                emitter.Duration = 10;
                emitter.Rate = UI.ParticleRate.Always(100);
                emitter.Generator = UI.ParticleGenerator.Same(info, UI.ParticlePoints.EngulfFromBottom(region.Rect, 3));
                Application.CurrentScene.AddEmitter(emitter.Create());

                info = new UI.ParticleInfo(Data.Particles.Cloud01);
                info.AddPhase(0, 0, 0xFA733C.ToColor(), 0.1, 0.1, 0, UI.ParticleTrajectory.Line(-90, 0.1));
                info.AddPhase(20, 40, 0xFA733C.ToColor(), 0.6, 0.5);
                info.AddPhase(30, 0, 0xFA733C.ToColor(), 0.2);
                emitter = new UI.ParticleEmitterInfo();
                emitter.Duration = 50;
                emitter.Rate = UI.ParticleRate.Always(20);
                emitter.Generator = UI.ParticleGenerator.Same(info, UI.ParticlePoints.EngulfFromBottom(region.Rect, 1));
                Application.CurrentScene.AddEmitter(emitter.Create());

                info = new UI.ParticleInfo(Data.Particles.Ball);
                info.AddPhase(0, 0, 0xFFB34C.ToColor(), 0.2, 0.2, 0, UI.ParticleTrajectory.Line(-90, 0.5));
                info.AddPhase(15, 60, 0xFFA34C.ToColor(), 1, 0.2);
                info.AddPhase(25, 0, 0x222222.ToColor(), 0.1, 0.2);
                emitter = new UI.ParticleEmitterInfo();
                emitter.Duration = 100;
                emitter.Rate = UI.ParticleRate.Always(2);
                emitter.Generator = UI.ParticleGenerator.Same(info, UI.ParticlePoints.EngulfFromBottom(region.Rect, 1));
                Application.CurrentScene.AddEmitter(emitter.Create());
            }
        }
    }
}
